#include "main.h"

int CharInBits (unsigned char * buf_in,unsigned char* buf_out,unsigned char * tables[],str_inf * inf)
{
	if (inf->u_bits == 0)	inf->u_bits = 8;
	if (inf->cur_pos == 0)	inf->cur_pos = 1;
	while (inf->cur_pos <= SIZE_BUF)	{
		if (inf->u_bits > 0)
			if (inf->ind_bits < (strlen((char *)tables[buf_in[inf->ind_char]])))
				if (tables[buf_in[inf->ind_char]][inf->ind_bits] == '1')	{	
					inf->u_bits --;	
					buf_out[inf->cur_pos-1] |= (__MARKER << inf->u_bits);
					inf->ind_bits ++;
				}
				else {	
					inf->u_bits--;	
					inf->ind_bits++;
				}
			else	
				if (inf->ind_char < (inf->max_pos - 1))	{
					inf->ind_char++;
					inf->ind_bits = 0;
				}
				else	{
						inf->ind_char = 0; 
						inf->ind_bits = 0;
						inf->max_pos = 0;
						return NEW_BUF_IN;
					}
		else	{	
			inf->u_bits = 8;
			inf->cur_pos++;
		}
	}
	if ((inf->ind_char == (inf->max_pos - 1)) && (inf->cur_pos == (SIZE_BUF + 1)))	{	
		inf->u_bits = 0;	
		inf->ind_bits = 0; 
		inf->ind_char = 0;
		inf->cur_pos --;
		return NEW_DATA;
	}
	else	{
		inf->cur_pos--; 
		inf->u_bits = 0;
		return NEW_BUF_OUT;	
	}
	return -24;
}